package com.maikec.utils.mybatis.base;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author maikec
 * @date 2018/7/17
 */
@Service
@Transactional(rollbackFor = Exception.class,timeout = 3600, readOnly = true)
public class BaseServiceImpl<T> {
    @Autowired
    private  PageMapper<T> pageMapper;

    /**
     * 新增
     * @param t pojo
     * @return int insert成功的总行数
     */
    public int insert(T t) {
        return pageMapper.insert(t);
    }

    /**
     * 根据id更新
     * @param t pojo
     * @return int 返回1更新成功、0失败
     */
    public int updateById(T t){
        return pageMapper.updateById(t);
    }

    /**
     * 根据id删除
     * @param t pojo
     * @return int delete成功的总行数
     */
    public int deleteById(T t){
        return pageMapper.deleteById(t);
    }

    /**
     * 根据id查询
     * @param t pojo
     * @return T 返回t
     */
    public T selectById(T t){
        return pageMapper.selectById(t);
    }

    /**
     * 根据给定的pojo查询列表
     * @param t
     * @return
     */
    public List<T> selectList(T t){
        return pageMapper.select(t);
    }

    /**
     * 查询单表分页信息
     * @param t t
     * @param pageNum pageNum
     * @param pageSize pageSize
     * @return pageInfo
     */
    public PageInfo<T> selectPageInfo(T t, int pageNum, int pageSize){
        return pageMapper.selectPageInfo(t, pageNum, pageSize);
    }
}
